package com.gdit.zax.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.gdit.zax.dao.VersionDao;
import com.gdit.zax.entitys.Version;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.LogUtil;

public class VersionDaoImpl implements VersionDao {
	private PreparedStatement ps;
	private ResultSet rs;
	
	private Connection conn;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	
	public VersionDaoImpl(Connection conn,HttpServletRequest request, HttpServletResponse response) {
		this.conn = conn;
		this.request = request;
		this.response = response;
	}
	
	
	public Version getLastVersion(String system) {
		String sql = "SELECT * from t_appversion where System=? ORDER BY AddTime desc";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, system);
			
			rs = ps.executeQuery();
			
			if (rs.next()) {
				Version ver = DBUtil.getobject(rs, Version.class);			
				return ver;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public Version hasUpdata(String system, String version) {
		Version ver = getLastVersion(system);
		if (!(ver.getSystem() == null || ver.getVersion() == null) || version == null) {
			version = version.trim();
			if (!ver.getVersion().equals(version)) {
				return ver;
			}
		}
		return null;
	}

	public ArrayList<Version> listAllVersion() {
		// TODO Auto-generated method stub
		return null;
	}

}
